<template>
  <transition name="slide">
    <div class="active-detail">
      <page-header title="活动详情"></page-header>
      <scroll class="detail-content" ref="detailScroll" :class="{'canBuy': canBuy}">
        <div>
          <div class="pic">
            <swiper class="pic-swiper" :options="swiperOption" v-if="data.picture && data.picture.length">
              <swiper-slide class="pic-swiper-item">
                <img :src="data.picture">
              </swiper-slide>
              <div class="swiper-pagination" slot="pagination"></div>
            </swiper>
          </div>
          <div class="info">
            <div class="title-price">
              <p class="title">{{data.name}}</p>
              <p class="price">¥{{data.money}}</p>
            </div>
            <p class="des" v-html="data.acabstract"></p>
          </div>
          <div class="stamp stamp04" v-for="item in couponList">
            <div class="par">
              <p>{{item.bean.name}}</p>
              <sub class="sign">￥</sub>
              <span>{{item.bean.discount}}</span>
              <sub>优惠券</sub>
            </div>
            <div class="copy" @click="couponReceive(item)">领取</div>
            <i></i>
          </div>
          <div class="detail">
            <ul class="info-detail">
              <li>
                <span>活动时间</span>
                <p>{{data.startTime}}</p>
              </li>
              <li>
                <span>活动地点</span>
                <p>{{data.acplace}}</p>
              </li>
              <li>
                <span>联系电话</span>
                <p>{{data.phone}}</p>
              </li>
              <li>
                <span>报名人数限制</span>
                <p>{{data.maxnum}}</p>
              </li>
              <li>
                <span>报名开始时间</span>
                <p>{{data.betime}}</p>
              </li>
              <li>
                <span>剩余名额</span>
                <p>{{data.maxnum-(appNum?appNum:0)}}</p>
              </li>
            </ul>
          </div>
          <div class="detail">
            <p class="class-title">活动详情</p>
            <!-- 课程安排 -->
            <ul>
              <li class="detail-box">
                <ul>
                   <li class="detail-item">
                    <p class="detail-item-text" v-html="data.content"></p>
                   </li>
                </ul>
              </li>
            </ul>
          </div>
        </div>
      </scroll>
      <ul class="buy" >
        <li @click="_gohome"><img src="../../assets/image/icon_home.png" alt=""><span>首页</span></li>
        <li><img src="../../assets/image/icon_share.png" alt=""><span>分享</span></li>
        <li><img src="../../assets/image/icon_ask.png" alt=""><span><a :href="'tel:' + data.phone">咨询</a></span></li>
        <div class="sign" @click="_sign()">报名</div>
      </ul>
    </div>
  </transition>
</template>

<script type="text/ecmascript-6">
  import PageHeader from 'components/page-header'
  import Scroll from 'components/scroll/scroll'
  import 'swiper/dist/css/swiper.css'
  import * as exampleApi from 'api/example'
  import { swiper, swiperSlide } from 'vue-awesome-swiper'
  export default {
    components: {
      PageHeader,
      Scroll,
      swiper,
      swiperSlide
    },
    data () {
      return {
        isPin: false,
        id: '',
        title: '',
        canBuy: true,
        classActive: 0,
        data: {},
        swiperOption: {
          direction: 'horizontal',
          pagination: {
            el: '.swiper-pagination',
            bulletClass: 'my-bullet',
            bulletActiveClass: 'my-bullet-active'
          }
        },
        swiperOption2: {
          slidesPerView: 3
          // spaceBetween: 30
        },
        appNum: 0,
        isCoupon: true,
        couponList: []
      }
    },
    created() {
      this.id = this.$route.params.id
      sessionStorage.removeItem('discount')
    },
    mounted() {
      this._initData()
      this.getCoupon()
    },
    methods: {
      _initData() {
        exampleApi.modePost('/api/public/wz/activity/details', {
          wzActivityId: this.id
        }).then(
          res => {
            if (res.data.data) {
              this.data = res.data.data.bean
              this.appNum = res.data.data.appNum
            }
          }
        )
      },
      getCoupon() {
        exampleApi.modePost('/api/public/wz/activity/coulist', {
          actId: this.id
        }).then(
          res => {
            if (res.data.data) {
              this.couponList = res.data.data.rows
              if (this.couponList.length === 0) {
                this.isCoupon = false
              }
            }
          }
        )
      },
      couponReceive(item) {
        let humanId = sessionStorage.getItem('studentId')
        if (humanId === '-1') {
          alert('您尚未登录，请先登录')
          this.$router.push({path: '/login'})
          return
        }
        exampleApi.modePost('/api/public/wz/activity/couponReceive', {
          orgId: sessionStorage.getItem('siteId'),
          couponId: item.bean.id,
          humanId: humanId
        }).then(
          res => {
            alert(res.data.msg)
          }
        )
      },
      _gohome() {
        this.$router.push('/home')
      },
      _sign() {
        this.$router.push({
          path: '/activity/signup' + this.id
        })
      }
    }
  }
</script>

<style lang="less" scoped>
  @import url('../../common/css/coupon.css');
  .slide-enter-active,.slider-leave-active {
    transition: all 0.3s
  }
  .slide-enter,.slide-leave-to {
    transform: translate3d(100%, 0, 0)
  }
  .active-detail {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right:0;
    background-color: #e6e6e6;
    z-index: 992;
    .detail-content{
      height:calc(~"100% - 84px");
      overflow: hidden;
      .pic{
        position: relative;
        width: 100%;
        height: 340px;
        // overflow: hidden;
        .pic-swiper{
          z-index: 8;
          .swiper-pagination{
            bottom: 20px;
            width: 100%;
            justify-content: center;
            display: flex;
            .my-bullet{
              margin:  0 5px;
              width: 10px;
              height: 10px;
              display: inline-block;
              border-radius: 100%;
              background-color: rgba(255, 255, 255, 0.7);
            }
            .my-bullet-active{
              background: #fff;
              opacity: 1;
            }
          }
          .pic-swiper-item{
            width: 100%;
            height: 340px;
          }
        }
        img{
          width: 100%;
          height: auto;
        }
        .fit{
          position: absolute;
          bottom: 0;
          left: 0;
          z-index: 10;
          width: 100%;
          height: 49px;
          background-color: rgba(0, 0, 0, 0.4);
          display: flex;
          padding-left: 24px;
          overflow: hidden;
          align-items: center;
          li{
            margin-right: 40px;
            font-size: 20px;
            color: #ffffff;
          }
        }
      }
      .info{
        height: 172px;
        padding: 26px;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        overflow: hidden;
        background-color: #fff;
        .title-price{
          display:flex;
          justify-content: space-between;
          align-items: center;
          .title{
            font-size: 32px;
            color: #333333;
            font-weight: bold;
          }
          .price{
            font-size: 32px;
            color: #ff0015;
            font-weight: bold;
            font-family: PingFang;
          }
        }
        .des{
          font-size: 22px;
          line-height: 34px;
          color: #999999;
        }
      }
      .class-title{
        width: calc(~"100% - 22px");
        box-sizing: border-box;
        height: 70px;
        line-height: 70px;
        font-size: 28px;
        color: #419eff;
        &::before {
          content: '';
          display: inline-block;
          vertical-align: text-bottom;
          width: 18px;
          height: 27px;
          background: url('../../assets/image/tip.png') no-repeat center / 100%;
          margin-right: 12px;
        }
      }
      .detail{
        padding: 0 22px;
        display: flex;
        flex-direction: column;
        align-items: center;
        background-color: #fff;
        margin-top: 20px;
        .class-title{
          border-bottom: 2px dashed #cccccc;
        }
        .red-title{
          margin-top: 32px;
          width: 100%;
          font-size: 24px;
          color: #fff;
          height: 44px;
          line-height: 44px;
          text-align: center;
          background: url('../../assets/image/title_bg.png') no-repeat center / auto 44px;
        }
        .detail-item{
          padding: 30px 0;
          position: relative;
          .detail-item-title{
            font-size: 24px;
            color: #419eff;
            font-weight: bold;
            &::before {
              content: '';
              display: inline-block;
              // vertical-align: text-bottom;
              width: 15px;
              height: 15px;
              border: 3px solid #419eff;
              box-sizing: border-box;
              border-radius: 50%;
              margin-right: 11px;
            }
          }
          .detail-item-text{
            font-size: 24px;
            line-height: 50px;
            color: #999999;
            font-family: Ping Fang;
          }
        }
      }
    }
    .detail-content.canBuy{
      height:calc(~"100% - 164px");
    }
    .buy{
      width: 100%;
      height: 80px;
      background-color: #fff;
      display: flex;
      .sign{
        width: 342px;
        flex: 0 0 342px;
        background-color: #ee4941;
        font-size: 28px;
        line-height: 80px;
        color: #ffffff;
        text-align: center;
      }
      li{
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        border-top: 1px solid#cccccc;
        border-left: 1px solid#cccccc;
        &:nth-child(1) {
          border-left: none;
        }
        span{
          margin-top: 8px;
          font-size: 20px;
          color: #999;
        }
        img{
          width: 26px;
          height: 26px;
        }
      }
    }
  }

  .info-detail{
    margin-top: 20px;
    width: 100%;
    padding:0 20px;
    box-sizing: border-box;
    background-color: #fff;
    li{
      height:80px;
      box-sizing: border-box;
      border-bottom: 1px solid #cccccc;
      display:flex;
      justify-content:space-between;
      align-items: center;
      span{
        font-size: 28px;
        color: #419eff;
      }
      p{
        font-size: 26px;
        color: #999999;
      }
    }
  }
</style>
